package com.ruyuan.rapid.common.config;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;

/**
 * 服务实例: 一个服务会对应多个服务实例
 * @author mac
 */
@Data
public class ServiceInstance implements Serializable {

    /**
     * 服务实例id ip:port
     */
    protected String serviceInstanceId;
    /**
     * 服务定义唯一id: uniqueId
     */
    protected String uniqueId;
    /**
     * 服务地址 ip:port
     */
    protected String address;
    /**
     * 标签信息
     */
    protected String tags;
    /**
     * 权重信息
     */
    protected Integer weight;
    /**
     * 服务注册的时间戳: 后面做负载均衡, warmUp预热
     */
    protected long registerTime;
    /**
     * 服务实例禁用启用
     */
    protected boolean enable = true;
    /**
     * 服务实例对应的版本号
     */
    protected String version;

    public ServiceInstance() {
    }

    public ServiceInstance(String serviceInstanceId, String uniqueId, String address, String tags,
                           Integer weight, long registerTime, boolean enable, String version) {
        this.serviceInstanceId = serviceInstanceId;
        this.uniqueId = uniqueId;
        this.address = address;
        this.tags = tags;
        this.weight = weight;
        this.registerTime = registerTime;
        this.enable = enable;
        this.version = version;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ServiceInstance that = (ServiceInstance) o;
        return serviceInstanceId.equals(that.serviceInstanceId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(serviceInstanceId);
    }
}
